package com.fw;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.fw.entity.User;
import com.fw.mapper.UserMapper;

public class Main {
    public static void main(String[] args) {
        String resource = "mybatis-config.xml";
        InputStream inputStream;
        try {
            inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session=sqlSessionFactory.openSession();
            UserMapper userMapper = session.getMapper(UserMapper.class);
            // List<User> list=userMapper.getAllUsers();
            // for(User user:list){
            //     System.out.println(user);
            // }

            User user=userMapper.findUserWithRoleById(1);
            System.out.println(user);
            System.out.println(user.getRole());
           
            
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
}